package com.ning.farm_income_back.controller;

import com.github.pagehelper.PageInfo;
import com.ning.farm_income_back.domain.Distributionrecords;
import com.ning.farm_income_back.domain.Distributionrules;
import com.ning.farm_income_back.domain.Users;
import com.ning.farm_income_back.dto.DistributionrecordsDto;
import com.ning.farm_income_back.service.DistributionService;
import com.ning.farm_income_back.vo.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/distribution")
public class DistributionController {
    @Autowired
    private DistributionService distributionService;

    //分页带条件查询
    @PostMapping("/page")
    public ResultVo<PageInfo> page(@RequestBody DistributionrecordsDto dto, @RequestParam(defaultValue = "1") Integer pageNum, @RequestParam(defaultValue = "3") Integer pageSize ) {

        //获取页面数据 总条数 总页数
        PageInfo pageInfo = distributionService.getPage(dto,pageNum,pageSize);

        return ResultVo.success("页面数据查询成功",pageInfo);
    }

    @GetMapping("/getRuleInfo")
    public ResultVo<Distributionrules> getRuleInfo() {
        Distributionrules date = distributionService.getRuleInfo();
        return ResultVo.success("查询成功",date);
    }

    //修改规则信息
    @PutMapping("/updateRuleInfo")
    public ResultVo updateRuleInfo(@RequestBody Distributionrules rules) {
        distributionService.updateRuleInfo(rules);
        return ResultVo.success("修改成功");
    }

    //执行分配
    @PostMapping("/executeDistribution")
    public ResultVo executeDistribution() {
        distributionService.executeDistribution();
        return ResultVo.success("执行分配成功");
    }

}
